﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MetaDataRepository;

namespace TestRepository
{
    public partial class Form1 : Form
    {
        private MetaDataRepository.Repository repositoryOfData;
        private mdExecution Execution;
        private mdSSISPackage ssisPackage;

        public Form1()
        {
            InitializeComponent();
            repositoryOfData = new Repository();
        }

        private void btnExecutionID_Click(object sender, EventArgs e)
        {
            Execution = repositoryOfData.GetExecution("DemoCommandLine", DateTime.Now);
        }

        private void btnAddSSISPackage_Click(object sender, EventArgs e)
        {
            ssisPackage = repositoryOfData.GetSSISPackage(Execution, "SSIS Test Package.dtsx");
        }

        private void btnGetExecution_Click(object sender, EventArgs e)
        {
            Execution = repositoryOfData.GetExecution(Int32.Parse(tbExecutionID.Text));
        }

        private void btnGetPackage_Click(object sender, EventArgs e)
        {
            ssisPackage = repositoryOfData.GetSSISPackage(1);
        }

        private void btnAddDatabase_Click(object sender, EventArgs e)
        {
            //repositoryOfData.GetDatabase(Execution, @"Data Source=.\SQL2008R2;Initial Catalog=master;Provider=SQLNCLI10.1;Integrated Security=SSPI;Application Name=SSIS-Package2-{74C1389E-D222-445C-AE84-935A9FA62CF3}.\SQL2008R2.master;Auto Translate=False;");
            repositoryOfData.GetDatabase(Execution, @"Server=localhost;database=SSIS_Meta;Integrated Security=SSPI;");
            repositoryOfData.GetDatabase(Execution, @"Provider=msolap;Data Source=localhost;");
        }

        private void btnDoDatabase_Click(object sender, EventArgs e)
        {
            SQLDBEnumerator dbEnum = new SQLDBEnumerator();
            dbEnum.Initialize(repositoryOfData, Execution);
            dbEnum.EnumerateDatabase(@"Server=.\SQL2008R2;Database=AdventureWorks2008R2;Integrated Security=SSPI;");
        }

        private void bntTestSSAS_Click(object sender, EventArgs e)
        {
            SSASEnumerator ssasEnum = new SSASEnumerator();
            ssasEnum.Initialize(repositoryOfData, Execution);
            ssasEnum.EnumerateServer(@"Provider=msolap;Data Source=.\SQL2008R2;");
        }

        private void btnObject_Click(object sender, EventArgs e)
        {
            mdDatabase db = repositoryOfData.GetDatabase(Execution, @"Server=localhost;database=SSIS_Meta;Integrated Security=SSPI;");
            repositoryOfData.GetObject(db, "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "name", "Table", "Short Description");
        }

        private void btnEnumSSIS_Click(object sender, EventArgs e)
        {
            SSISEnumerator ssisEnum = new SSISEnumerator();
            ssisEnum.Initialize(repositoryOfData, Execution);
            ssisEnum.EnumerateFileSystemPackages(new string[] {@"\Source\TestData" }, false);
        }
    }
}
